<?php require_once "function.php"; ?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Patient Summery</title></head>

<body>
<a href="ntuh.php" target="_parent">登入</a>
<a href="<?php echo $url['hospitalization'];?>" target="Canvas">住院</a>
<a href="<?php echo $url['sono'];?>" target="Canvas">Sono</a>
<a href="recentpatho.php?id=<?php echo $_GET["id"]; ?>" target="Canvas">病理</a>
<a href="<?php echo $url['phpmyadmin'];?>" target="Canvas">資料庫</a>
<a href="<?php echo $url['telephone'];?><?php echo $sessionid; ?>" target="Canvas">電話</a>
<a href="<?php if($_GET['id']!=NULL){
                 echo 'PACS.php?id='.$_GET['id'];
               }else{
                echo $url['WEB1000'].$sessionid;
               }?>" target="Canvas">PACS</a>
<a href="<?php echo $url['portal']['medicalrecord'].$_GET['id'];?>" target="_new">簡史</a>
<a href="<?php echo "lab.php?id=".$_GET['id']; ?>" target="Canvas">檢驗</a>
<a href="angio.php?id=<?php echo $_GET["id"]; ?>" target="Canvas">Angio</a>

<form target="_parent" method="POST" action="ntuhFrame.php" name=f>
<br>查詢最近CRE和病理診斷</p>
病歷號：<input autocomplete="off" maxlength=7 name=id size=7 title="請輸入病歷號" value='<?php echo $_GET["id"]; ?>'><input type=submit value="查詢"><input type=submit name=Cr value='Cre'>
</form>
<hr>
<?php
  $mesg1="<font color=#ff0000>查無近一年內 creatinine 資料</font>";

  if($_GET["id"]==NULL){
    $id=$_POST["id"];
  }else $id=$_GET["id"];
  
  if(!isset($id)) exit;
    
  $name=getName($id);
  if($name['name']==NULL) exit('無此病歷號！');
  $caseno=getLabCaseno($id);
  $age=ageOI($name['birthdate'],date('Y.m.d',time()));
  echo $id.' '.$name['name'].' '.$name['gender'].' ';

  //處理不同年紀顯示
  if($age['y']==0&&$age['m']>=1) echo "<font color=#ff0000>".$age['m'].'個月'.$age['d'].'天</font><br>';
  if($age['y']==0&&$age['m']==0) echo "<font color=#ff0000>".$age['d'].'天</font><br>';
  if($age['y']<=5&&$age['y']>=1) echo $age['y'].'歲'.$age['m'].'個月<br>';
  if($age['y']>=70) echo "<font color=ff0000>".$age['y']."歲</font><br>";
  if($age['y']>=6&&$age['y']<70) echo $age['y'].'歲<br>';

  if($_POST["Cr"]=="Cre"||$_GET["Cr"]=="Cre"){
  //處理creatinine及GFR
  if(is_string($caseno)){
    $cr=substr($caseno,17,strlen($caseno)-17);
    $GFR=MDRD();
    if($cr>2) $caseno=str_replace(' '.$cr,"<font color=#ff0000> ".$cr."</font>",$caseno);
    echo $caseno.'<br>';
    if($age['y']>=18) echo '(MDRD GFR = '.$GFR.')';
  }
  if(is_array($caseno)&&!empty($caseno)){
    $cre=getLabDept($id,$caseno);
    if($cre!=NULL){
      $cr=substr($cre,17,strlen($cre)-17);
      $GFR=MDRD();
      if($cr>2) $cre=str_replace(' '.$cr,"<font color=#ff0000> ".$cr."</font>",$cre);
      echo $cre.'<br>';
      if($age['y']>=18) echo '(MDRD GFR = '.$GFR.')';
    }else{
       echo $mesg1;
    }
  }
  if(is_array($caseno)&&empty($caseno)) echo $mesg1;
  if($caseno==NULL) echo $mesg1;
  }

  $pathlist=PathList($id);
  $path=PathRPT($pathlist[0]['PathCode']);

  echo "<hr>";
  if(!empty($pathlist)){
    echo "最近一次的病理報告："."<br>";
    echo '日期：'.ConvDate($pathlist[0]['SpecimenGetDate'],'/')."<br>";
    foreach($path as $p){
      if(!is_string($p)){
        echo '器官：'.$p['organ']."<br>";
	    echo '診斷：'.$p['diagnosis']."<br>";
	    echo "<hr>";
      }
    }
  }else echo "無任何病理報告";
?>

</p>

</body>
</html>
